package com.qianyu.project.mapper.provider.gs;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * @author gs
 * @date create in 2021/2/3 16:24
 */
public class TenderBiddingHistoryMapperProvider {

    public String selectPageList(IPage page, Map<String, String> params) {
        return new SQL() {
            {
                SELECT("tbh.*,pi.project_name,tc.company_name,pt.type_name as project_type");
                FROM("tender_bidding_history tbh,tender_purchase_plan tpp,project_info pi,tender_company tc,project_type pt");
                WHERE("tbh.tender_id=tpp.id and tbh.company_id=tc.id");
                WHERE("tpp.pro_id=pi.id and pt.type_id=pi.project_type");
                if (!ObjectUtils.isEmpty(params.get("projectName"))) {
                    WHERE("pi.project_name like '%${params.projectName}%'");
                }
                if (!ObjectUtils.isEmpty(params.get("status"))) {
                    WHERE("tbh.status=#{params.status}");
                }
                if (!ObjectUtils.isEmpty(params.get("tenderId"))) {
                    WHERE("tbh.tender_id=#{params.tenderId}");
                }
                if (!ObjectUtils.isEmpty(params.get("projectType"))) {
                    WHERE("pt.type_id=#{params.projectType}");
                }
                if (!ObjectUtils.isEmpty(params.get("companyName"))) {
                    WHERE("tc.company_name like '%${params.companyName}%'");
                }
                //判断是查看自己的还是对手的
                if (!ObjectUtils.isEmpty(params.get("type"))) {
                    switch (params.get("type")) {
                        case "we":
                            WHERE("tbh.company_id=#{params.companyId}");
                            break;
                        case "opponent":
                            WHERE("tbh.company_id!=#{params.companyId} and tbh.status='2'");
                            break;
                    }
                }
            }
        }.toString();
    }
}
